package com.tian.print.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Description: 网络判断
 * Author：skyTian
 * Time:2017/11/10 13:36
 * CopyRight:com,sky
 */
public class NetWorkUtils {

    /**
     * 判断是否网络通畅
     *
     * @param context 系统服务的使用 最好使用ApplicationContext，避免一些莫名内存泄漏
     * @return
     */
    public static boolean isNetworkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }
        return false;
    }


}
